package org.bozo.im.service.protocols.xmpp.util.namespace;

import java.security.InvalidParameterException;
import java.util.Hashtable;

public enum Namespace {

	BIND("bind"),
	CAPABILITIES("capabilities"),
	ERROR("error"),
	JABBER_CLIENT("jabber"),
	ROSTER("roster"),
	SASL("sasl"),
	SESSION("session"),
	STARTTLS("starttls"),
	STREAM("stream"),
	XML("xml");

	private static Hashtable<String, Namespace> mNamespaces;
	
	static {
		mNamespaces = new Hashtable<String, Namespace>();
		addNamespace(BIND);
		addNamespace(CAPABILITIES);
		addNamespace(ERROR);
		addNamespace(JABBER_CLIENT);
		addNamespace(ROSTER);
		addNamespace(SASL);
		addNamespace(SESSION);
		addNamespace(STARTTLS);
		addNamespace(STREAM);
		addNamespace(XML);
	}
	
	private static void addNamespace(Namespace pNamespace) {
		mNamespaces.put(pNamespace.getNamespace(), pNamespace);
	}
	
	public static Namespace valueOfNamespace(String pNamespace) {
		
		if (pNamespace == null)
			return null;
		
		return mNamespaces.get(pNamespace);
	}
	
	private String mValue;
	
	private Namespace(String pValue) {
		mValue = pValue;
	}
	
	public String getPrefix() {
		return mValue;
	}
	
	public String getNamespace() {

		String lNamespace;

		switch (this) {

		case BIND:
			lNamespace = "urn:ietf:params:xml:ns:xmpp-bind";
			break;

		case CAPABILITIES:
			lNamespace = "http://jabber.org/protocol/caps";
			break;
			
		case ERROR:
			lNamespace = "urn:ietf:params:xml:ns:xmpp-streams";
			break;
			
		case JABBER_CLIENT:
			lNamespace = "jabber:client";
			break;

		case ROSTER:
			lNamespace = "jabber:iq:roster";
			break;
			
		case SASL:
			lNamespace = "urn:ietf:params:xml:ns:xmpp-sasl";
			break;

		case SESSION:
			lNamespace = "urn:ietf:params:xml:ns:xmpp-session";
			break;
			
		case STARTTLS:
			lNamespace = "urn:ietf:params:xml:ns:xmpp-tls";
			break;
			
		case STREAM:
			lNamespace = "http://etherx.jabber.org/streams";
			break;

		case XML:
			lNamespace = "http://www.w3.org/XML/1998/namespace";
			break;
			
		default:
			throw new InvalidParameterException("This namespace ID is not supported yet");
		}

		return lNamespace;
	}

	
}
